home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
386
/
utility
/
cmd_test.s
< prev
next >
Wrap
Text File
|
1985-11-19
|
10KB
|
229 lines
; Program Name: CMD_TEST.S
; Version 1.004
; Assembly Instructions:
; Assemble in "PC-relative" mode and save with a TOS extension.
; Execution Instructions:
; Execute program CMD_TEST.TOS from the desktop. After reading the
; program's output on the screen, terminate execution by pressing the
; Return key.
; Function:
; This program is used to compare the relative speed of the command
; line processing algorithms used in SPEED_1, SPEED_2 and SPEED_3.
; Description:
; Three command line processing algorithms are executed 10,000 times.
; The elapsed time and requisite memory for each algorithm is printed to
; the screen. So that this program need not be executed as a TTP program,
; the command line is salted with a declared string.
release_excess_memory:
lea program_end, a0 ; Put "end of program" address in A0.
movea.l 4(a7), a1 ; Put "basepage" address in A1.
movea.l a1, a5 ; Copy to A5 for command line access.
trap #6 ; Calculate program size and release memory.
lea stack, a7 ; Point A7 to this program's stack.
mainline:
lea heading, a0
bsr print_string
salt_command_line:
lea salt, a0 ; Fetch pointer to ersatz command line input.
movem.l (a0), d0-d3 ; Move it to registers.
movem.l d0-d3, $80(a5) ; Copy to actual command line address.
speed_1_algorithm:
lea speed_1_msg, a0
bsr print_string
move.l #9999, d4 ; Initialize counter for 10000 executions.
trap #3 ; Get start time.
move.l d0, d5 ; Copy for calculations.
speed_1_loop:
lea $80(a5), a4 ; Fetch address of parameters.
move.b (a4)+, d0 ; Fetch parameter line character count.
lea program_name_1, a3 ; Load buffer address.
subq.b #1, d0 ; Set up counter.
ext.w d0 ; Extend to match the size of the dbra
; instruction.
fetch_character:
move.b (a4)+, (a3)+ ; Store character.
dbra d0, fetch_character ; Loop until D0 becomes negative.
move.b #0, (a3) ; Finish with a NULL.
create_file_name: ; Create a file to accept standard output.
lea filename_1, a4 ; Load buffer address.
lea program_name_1, a3 ; Load buffer address.
copy_name:
move.b (a3)+, (a4)+
cmpi.b #$2E, (a3) ; Is next byte of program_name the period?
bne.s copy_name ; Continue looping until period is seen.
move.b #$2E, (a4)+ ; Add a period.
move.b #$44, (a4)+ ; Add letter 'D'.
move.b #$41, (a4)+ ; Add letter 'A'.
move.b #$54, (a4)+ ; Add letter 'T'.
move.b #0, (a4) ; Add a NULL.
speed_1_memory:
dbra d4, speed_1_loop ; Loop until D4 becomes negative.
trap #3 ; Get end time.
bsr convert_and_print_time
speed_2_algorithm:
lea speed_2_msg, a0
bsr print_string
move.l #9999, d4 ; Initialize counter for 10000 executions.
trap #3 ; Get start time.
move.l d0, d5 ; Copy for calculations.
speed_2_loop:
lea input_line, a3 ; Fetch location to contain command line.
lea output_line_2, a4 ; A second location: for filename.
movem.l $80(a5), d0-d3 ; Move 16 bytes of command line to 4 registers.
movem.l d0-d3, (a3) ; Move them to address "input_line".
movem.l d0-d3, (a4) ; Move them to address "output_line".
move.b $80(a5), d0 ; Fetch command line ASCII character count.
ext.w d0 ; Extend to word for next instruction.
move.b #0, 1(a3,d0.w) ; Store a null at end of command line input.
move.b #0, 1(a4,d0.w) ; Same for filename buffer.
insert_filename_suffix:
move.b #$44, -2(a4,d0.w) ; Insert letter 'D'.
move.b #$41, -1(a4,d0.w) ; Insert letter 'A'.
move.b #$54, 0(a4,d0.w) ; Insert letter 'T'.
speed_2_memory:
dbra d4, speed_2_loop ; Loop until D4 becomes negative.
trap #3 ; Get end time.
bsr convert_and_print_time
speed_3_algorithm:
lea speed_3_msg, a0
bsr print_string
move.l #9999, d4 ; Initialize counter for 10000 executions.
lea $80(a5), a5 ; Fetch command line address.
trap #3 ; Get start time.
move.l d0, d5 ; Copy for calculations.
speed_3_loop:
; NOTE: The first instruction, below, is not used in the actual SPEED_3
; algorithm, but it must be included here to reset A3 to the
; correct address each time through the loop. This instruction
; adds 4 clock periods per loop, 40000 clock periods for the
; 10000 loops, which is 5 milliseconds. The accuracy of this error
; calculation was confirmed by executing CMD_TEST.TOS with and
; without the instruction in the loop. The 5 msec error is equal to
; one system clock tick, therefore, when the loop end-time is obtained
; with the trap #3 invocation, 1 clock tick is subtracted before the
; loop time is calculated.
; The memory occupied by this instruction is not included in the
; value reported for the algorithm's requisite memory.
movea.l a5, a3
start_memory:
lea output_line_3, a4 ; Fetch location to contain command line.
movem.l (a3), d0-d3 ; Move 16 bytes of command line to 4 registers.
movem.l d0-d3, (a4) ; Move them to address "command_line".
move.b (a3)+, d0 ; Fetch command line ASCII character count.
ext.w d0 ; Extend to word for next instruction.
move.b #0, 1(a4,d0.w) ; Store a null at end of string.
lea program_name_ptr, a0 ; Fetch address of pointer to program name.
move.l a3, (a0) ; Store address of filename string in pointer.
move.b #0, 0(a3,d0.w) ; Replace $0D at end of program name with NULL.
_insert_filename_suffix:
move.b #$44, -2(a4,d0.w) ; Insert letter 'D'.
move.b #$41, -1(a4,d0.w) ; Insert letter 'A'.
move.b #$54, 0(a4,d0.w) ; Insert letter 'T'.
speed_3_memory:
dbra d4, speed_3_loop
trap #3
subq.w #1, d0 ; Subtract 1 clock tick to correct time.
bsr.s convert_and_print_time
speed_1_requisite_memory:
lea speed_1_memory_msg, a0
bsr.s print_string
lea speed_1_loop, a1 ; Calculate number of bytes occupied by the
lea speed_1_memory, a0 ; instructions in the loop, then print.
bsr.s calculate_and_print_requisite_memory
speed_2_requisite_memory:
lea speed_2_memory_msg, a0
bsr.s print_string
lea speed_2_loop, a1 ; Calculate number of bytes occupied by the
lea speed_2_memory, a0 ; instructions in the loop, then store.
bsr.s calculate_and_print_requisite_memory
speed_3_requisite_memory:
lea speed_3_memory_msg, a0
bsr print_string
lea start_memory, a1 ; Calculate number of bytes occupied by the
lea speed_3_memory, a0 ; instructions in the loop, then print.
bsr.s calculate_and_print_requisite_memory
wait_for_keypress:
move.w #8, -(sp) ; Function = c_necin = GEMDOS $8.
trap #1 ; GEMDOS call.
addq.l #2, sp ; Reposition stack pointer at top of stack.
terminate:
move.w #0, -(sp)
trap #1
print_string: ; Expects address of string to be in A0.
pea (a0) ; Push address of string onto stack.
move.w #9, -(sp) ; Function = c_conws = GEMDOS $9.
trap #1 ; GEMDOS call
addq.l #6, sp ; Reset stack pointer to top of stack.
rts
convert_and_print_time:
sub.l d5, d0 ; Subtract start time from end time.
mulu #5, d0 ; Convert to milliseconds.
move.l d0, d1 ; Convert to ASCII decimal.
trap #4
bsr print_string
lea time_label, a0
bsr print_string
rts
calculate_and_print_requisite_memory:
suba.l a1, a0
move.l a0, d1 ; Transfer requisite memory for trap call.
print_speed_1_requisite_memory:
trap #4 ; Returns address of decimal string in A0.
bsr print_string
lea memory_label, a0
bsr print_string
rts
data
salt: dc.b $B,"PRG_5AP.TOS",$D,0,0,0,0
heading: dc.b $D,$A,"CMD_TEST Execution Results",$D,$A,$D,$A,0
speed_1_msg: dc.b " SPEED_1 algorithm time: ",0
speed_2_msg: dc.b " SPEED_2 algorithm time: ",0
speed_3_msg: dc.b " SPEED_3 algorithm time: ",0
time_label: dc.b " milliseconds",$D,$A,0
speed_1_memory_msg: dc.b $D,$A," SPEED_1 algorithm requisite memory: ",0
speed_2_memory_msg: dc.b " SPEED_2 algorithm requisite memory: ",0
speed_3_memory_msg: dc.b " SPEED_3 algorithm requisite memory: ",0
memory_label: dc.b " bytes",$D,$A,0
align
bss
program_name_1: ds.l 4 ; Program name buffer for SPEED_1 algorithm.
filename_1: ds.l 4 ; Filename buffer for SPEED_1 algorithm.
input_line: ds.b 1 ; Command line buffer for SPEED_2 algorithm.
program_name_2: ds.b 15 ; Program name buffer for SPEED_2 algorithm.
output_line_2: ds.b 1 ; Second command line buffer for SPEED_2.
filename_2: ds.b 15 ; Filename buffer for SPEED_2 algorithm.
program_name_ptr: ds.l 4 ; Pointer to filename in command line for SPEED_3.
output_line_3: ds.b 1 ; Command line buffer for SPEED_3 algorithm.
filename_3: ds.b 15 ; Filename buffer for SPEED_3 algorithm.
ds.l 96 ; Program stack.
stack: ds.l 0 ; Address of program stack.
program_end: ds.l 0
end